'''
反射：通过字符串映射或修改程序运行时的状态，属性，方法
getattr(object,name,__default=None)根据字符串去获取obj对象里的对应的方法的内存地址
hasattr(object,name——str)判断一个对象里是否有对应的name_str字符串的方法映射
setattr(obj,y,v)  设置一个属性
delattr(x,y)
'''
def bulk(self):
    print("%s is yelling"%self.name)

class Dog(object):
    def __init__(self,name):
        self.name = name

    def eat(self,food):
        print("%s is eating..."%self.name,food)

d = Dog('xiaowang')
choice = input('>>:').strip()
'''
print(hasattr(d,choice))
print(getattr(d,choice))#映射出内存对象地址
getattr(d,choice)()
'''
if hasattr(d,choice):
    # delattr(d,choice)

    func = getattr(d,choice)
    func('baozi')

    # attr = getattr(d,choice)
    # print(attr)
    # setattr(d,choice,'wangwang')
    # print(attr)
else:
    setattr(d,choice,bulk)#动态装方法
    d.talk(d)#d.talk=bulk,所以不能输入bulk

    # setattr(d,choice,22)#加静态属性
    # print(getattr(d,choice))


print(d.name)